const app = getApp();
var request = app.request;
var util = require('../../../utils/util.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    url: app.globalData.setting.url,
    statusBar: app.globalData.statusBar,
    userInfo: app.globalData.userInfo,
    type: 1,
    goods:[],
    code: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getGoods();
  },
  changeType(e) {
    this.setData({
      type: e.currentTarget.dataset.type
    })
  },
  back() {
    wx.navigateBack();
  },
  copy() {
    wx.setClipboardData({
      data: this.data.userInfo.mobile,
      success: function(res) {
        wx.showToast({
          title: '复制成功',
          icon: 'success',
          duration: 2000
        });
      }
    });
  },
  submitInvite() {
    console.log(1)
    if(!this.data.code) {
      console.log(2)
      wx.showToast({
        title: '邀请码不能为空',
        icon: 'none'
      })
      return;
    }
    request.get('/api/user/bindLeaderByCode', {
      data: {
        invite_code: this.data.code
      },
      success: function (res) {
        wx.showToast({
          title: '提交成功',
        })
      }
    });
  },
  setInviteCode(e){
    this.setData({
      code: e.detail.value
    })
  },
  getGoods() {
    var that = this;
    request.get('/api/goods/getGoods', {
      data: {
        'pid': 0,
        'id': 7,
        'sale': 0,
        'price': 0
      },
      success: function (res) {
        that.setData({
          goods: res.data.result
        });
      }
    });
  },
})